<?php

namespace app\home\controller;
use think\facade\View;
use think\facade\Db;
use think\facade\Lang;

/**
 * ============================================================================
 * DSKMS多用户商城
 * ============================================================================
 * 版权所有 2014-2028 长沙德尚网络科技有限公司，并保留所有权利。
 * 网站地址: http://www.csdeshang.com
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
 * 不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
 * 控制器
 */
class Memberexambanksuggest extends BaseMember {

    public function initialize() {
        parent::initialize(); // TODO: Change the autogenerated stub
        Lang::load(base_path() . 'home/lang/'.config('lang.default_lang').'/memberexambanksuggest.lang.php');
    }

    /*
     * 反馈列表
     */

    public function index() {
       $exambanksuggest_model = model('exambanksuggest');
//        $exambanksuggest_list = Db::name('exambanksuggest')->where('es.exambanksuggest_memberid', session('member_id'))->alias('es')->field('es.*,e.exambank_question')->order('exambanksuggest_id desc')->join('exambank e', 'es.exambank_id=e.exambank_id')->paginate(10);
       $exambanksuggest_list = $exambanksuggest_model->getExambanksuggestList(array('exambanksuggest_memberid'=> session('member_id')),'*',10);
        /* 设置买家当前菜单 */
        $this->setMemberCurMenu('member_exambanksuggest');
        /* 设置买家当前栏目 */
        $this->setMemberCurItem('index');
        View::assign('exambanksuggest_list', $exambanksuggest_list);
        View::assign('show_page',  $exambanksuggest_model->page_info->render());
        return View::fetch($this->template_dir . 'index');
    }

    public function add(){
        $exambank_id = intval(input('param.exambank_id'));
        if ($exambank_id <= 0) {
            $this->error(lang('param_error'),url('Index/index'));
        }
        //获取题目信息
        $exambank = model('exambank')->getOneExambank(array('exambank_id' => $exambank_id));
        if(empty($exambank)){
            $this->error(lang('exambank_id_no'),url('Index/index'));
        }
        if (request()->isPost()) {
            $exambanksuggest_model = model('exambanksuggest');
            $param = array();
            $param['exambanksuggest_describe'] = input('param.exambanksuggest_describe');
            $param['exambank_id'] = $exambank_id;
            $param['exambanksuggest_addtime'] = TIMESTAMP;
            $param['exambanksuggest_memberid'] = session('member_id');
            $param['exambanksuggest_membername'] = session('member_name');

            $result = $exambanksuggest_model->addExambanksuggest($param);

            if ($result) {
                ds_json_encode(10000, lang('ds_common_op_succ'));
            } else {
                ds_json_encode(10001, lang('ds_common_op_fail'));
            }
        } else {
            $this->setMemberCurMenu('member_exambanksuggest');
            /* 设置买家当前栏目 */
            $this->setMemberCurItem('add');
            View::assign('exambank', $exambank);
            return View::fetch($this->template_dir . 'add');
        }
    }

    /**
     * 用户中心右边，小导航
     *
     * @param string $menu_type 导航类型
     * @param string $menu_key 当前导航的menu_key
     * @param array $array 附加菜单
     *
     * @return
     */
    public function getMemberItemList() {
        $menu_array = array(
            array(
                'name' => 'index',
                'text' => lang('memberexambanksuggest_list'),
                'url' => url('Memberexambanksuggest/index')
            ),
        );
        
        

        return $menu_array;
    }

}
